package ClassWork.Work_01;

import java.util.Scanner;

public class RandomNumbers {
    public static void print(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }
    public static int searchArry(int[] arr, int rand){
        int index = -1;
        for(int i = 0; i < arr.length; i++){
            if(arr[i] == rand){
                index = i;
                break;
            }
        }
        return index;
    }
    public static int[] random(int x){
        int n = 0;
        int[] arr = new int[x];
        while(true){
            int rand = (int)(Math.random() * arr.length + 1);
            int index = searchArry(arr,rand);
            if(index == -1){
                arr[n] = rand;
                n++;
                if(n == x){
                    break;
                }
            }
        }
        return arr;
    }
    public static int length(){
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入数组长度：");
        int length = sc.nextInt();
        return length;
    }
    public static void main(String[] args) {
        int x = length();
        int[] arr = random(x);
        print(arr);
    }
}
